package com.xwm93up.basic.lambdatips.Sorted;

import com.google.common.collect.Lists;
import com.xwm93up.basic.lambdatips.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Objects;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2021/12/2 16:43
 */
public class Test1 {
    public static void main(String[] args) {
        ArrayList<Student> students = Lists.newArrayList(
                new Student("Tom", 10),
                new Student("Jerry", 12),
                new Student("Bob", 11));
        System.out.println("排序前：" + students);
        Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                // 根据name属性排序， 比较的是字母的ASCII码表十进制
                //return o1.getName().compareTo(o2.getName());

                // 根据age属性值排序， 升序排序
                //return o1.getAge() - o2.getAge();

                // 根据age属性值排序， 降序排序
                return o2.getAge() - o1.getAge();
            }
        });
        System.out.println("排序后：" + students);
        System.out.println(Objects.equals(students.get(0), new Student("Jerry", 12)));
    }
}
